package com.example.ccj.b.c.custom.tree;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.example.ccj.R;
import com.example.ccj.b.c.dialog.DialogBase;

import java.util.ArrayList;
import java.util.List;

/**
 * 从树状结构中选择数据返回dialog
 * @author 驰珺
 * whechat   : chijun9
 * create at : 2024/11/22 20:41
 */
public class SelectTreeListDataDialog extends DialogBase {

    List<TreeMode> treeModeList;
    String treeViewName;
    IResultTreeDataListener resultTreeDataListener;
    /**
     *
     * @param context 上下文
     */
    public SelectTreeListDataDialog(@NonNull Context context, String treeViewName, List<TreeMode> treeModeList ,IResultTreeDataListener resultTreeDataListener) {
        super(context);
        this.treeModeList = treeModeList;
        this.treeViewName = treeViewName;
        this.resultTreeDataListener = resultTreeDataListener;
    }

    TreeView treeView;

    @Override
    public void onInit() {
        isCanClose(true);
        setLayout(R.layout.dialog_select_tree_list_data);
        setAlpha(1f);//透明度
        isCanClose(true);//点击允许关闭
        isShowBackground(false);//不显示背景
        setShowHeightRatio(true);//按比例显示
        setHeightRatio(0.7);//高度显示比例
        showInBottom();//底部弹出
        setFull(true);//是否铺满
        goneTitleLeftImage();

        treeView = findViewById(R.id.dialog_select_tree_list_data_tree);
        setTitleCenterText(treeViewName);
        setTitleRightText("OK").setOnClickListener(V->{
            if (resultTreeDataListener!= null) resultTreeDataListener.result(treeView.getSelectTreeModeMap());
            dismiss();
        });

        treeView.setTitleName(treeViewName)
                .setShowLevel(2) // 显示级别
                .setOnlyShowMuLu(false) //初始加载是否只显示目录
                .setSuoJinJiBie(3)//缩进级别
                .setDataDefaultImageResource(com.example.ccj.R.mipmap.bar_code)//数据默认图标
                .setMuLuDefaultImageResource(com.example.ccj.R.mipmap.drawing_boar_brush_gray)//目录默认图标
                .setData(treeModeList)//数据
                //选中或取消选中回调
                .setSelectTreeListener(null)
                .show();//绘制

    }

}
